<div id="updateUserModal" class="modal fade" tabindex="-1" data-width="400">
	<div class="modal-dialog">
		<div class="modal-content">

			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
				<h4 class="modal-title">用户资料维护</h4>
			</div>

			<form class="form-horizontal form-bordered form-row-stripped" id="updateUserForm">
				<div class="modal-body">
					<div class="row">
						<div class="col-md-12">
							<div class="form-body">
								<div class="form-group">
									<label class="control-label col-md-3"> 邮箱: </label>
									<div class="col-md-5">
										<input type="text" name="email" id="email" readonly="readonly"
											value="${userInfo.user.email}" placeholder="邮箱"
											class="form-control" />
									</div>
								</div>
								<div class="form-group">
									<label class="control-label col-md-3"> 姓名: </label>
									<div class="col-md-5">
										<input type="text" name="name" id="name"
											value="${userInfo.user.name!}" placeholder="姓名"
											class="form-control" />
									</div>
								</div>
								<div class="form-group">
									<label class="control-label col-md-3"> 手机: </label>
									<div class="col-md-5">
										<input type="text" name="mobile" id="mobile"
											value="${userInfo.user.mobile!}" placeholder="手机"
											class="form-control" />
									</div>
								</div>
								<input type="hidden" name="type" value="${userInfo.user.type}"/>
								<input type="hidden" name="id" value="${userInfo.user.id}"/>
							</div>
						</div>
					</div>
				</div>
				
				<div class="modal-footer">
					<button type="button" data-dismiss="modal" class="btn" >取消</button>
					<button type="submit" id="userUpdateBtn" class="btn btn-primary" disabled="disabled">确定</button>
				</div>
			
			</form>
		</div>
	</div>
</div>
<!-- 重置密码 -->
<div id="resertPasswordModal" class="modal fade" tabindex="-1" data-width="400">
	<div class="modal-dialog">
		<div class="modal-content">

			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
				<h4 class="modal-title">密码重置</h4>
			</div>

			<form class="form-horizontal form-bordered form-row-stripped">
				<div class="modal-body">
					<div class="row">
						<div class="col-md-12">
							<div class="form-body">
								<input type="hidden" value="${userInfo.user.id}" id="currentLoggedUserId"/>
								<div class="form-group">
									<label class="control-label col-md-4"> 旧密码: </label>
									<div class="col-md-5">
										<input type="password" id="passwordOld" placeholder="密码" class="form-control"/>
									</div>
								</div>
								<div class="form-group">
									<label class="control-label col-md-4"> 新密码: </label>
									<div class="col-md-5">
										<input type="password" id="passwordNewC" value="" placeholder="密码" class="form-control" />
									</div>
								</div>
								<div class="form-group">
									<label class="control-label col-md-4"> 确认密码: </label>
									<div class="col-md-5">
										<input type="password" id="passwordNewC2" value="" placeholder="密码" class="form-control" />
									</div>
								</div>
							</div>
						</div>
					</div>
				</div>
				<div class="modal-footer">
					<button type="button" data-dismiss="modal" class="btn" >取消</button>
					<button type="button" id="resertPasswordBtn" onclick="resertPasswordCommit()" class="btn btn-primary">确定</button>
				</div>
			
			</form>
		</div>
	</div>
</div>
<script>
	$(function () {
        $('#updateUserForm').bootstrapValidator({
　　　　　　	message: 'This value is not valid',
            　		feedbackIcons: {
                　　　　　　　　valid: 'glyphicon glyphicon-ok',
                　　　　　　　　invalid: 'glyphicon glyphicon-remove',
                　　　　　　　　validating: 'glyphicon glyphicon-refresh'
            　　　　　　　　   },
            fields: {
                name: {
                    validators: {
                        notEmpty: {
                            message: '用户名不能为空'
                        }
                    }
                },
                mobile: {
                    validators: {
                        notEmpty: {
                            message: '手机号不能为空'
                        },
	                     regexp: {
	                         regexp: /^1(3|4|5|7|8)\d{9}$/,
	                         message: '请输入正确的手机号码'
	                     }
                    }
                }
            }
        }).on('success.form.bv', function(e) {
            // 阻止默认事件提交
            e.preventDefault();
            disable("userUpdateBtn");
    		$.post('${request.contextPath}/user/update',
   				$("#updateUserForm").serialize(),
   		        function(data){
   		            if(data.status == 200){
   						toastr.success("操作成功，系统将自动刷新");  
   						reload(3000);
   				    }else{
   				    	enable("userUpdateBtn");
   				    	toastr.error("操作失败！"+data.message);  
   				    }
   		        }, 'json');
        });
    });

	//发送更新请求
	function resertPasswordCommit(){
		if(!$("#passwordOld").val() || $("#passwordNewC").val() == $("#passwordOld").val()) {
			alert("新密码不能与旧密码一致");
			return;
		}
		if(!$("#passwordNewC").val() || $("#passwordNewC").val() != $("#passwordNewC2").val()) {
			alert("两次密码不一致");
			return;
		}
		disable("resertPasswordBtn");
		$.post('${request.contextPath}/user/resetPassword',
				{
					uid : $("#currentLoggedUserId").val(),
					passwordOld : $("#passwordOld").val(),
					passwordNew : $("#passwordNewC").val()
				},
		        function(data){
		            if(data.status == 200){
						toastr.success("操作成功，系统将自动刷新");  
						reload(3000);
				    }else{
				    	toastr.error("操作失败！"+data.message);  
				    	enable("resertPasswordBtn");
				    }
		        }, 'json');
	}
</script>
